// 连接数据库
const mongoose = require('./db');

// 菜品分类表
const categorySchema = new mongoose.Schema({
    cname: String //菜品分类名称
})

const categoryModel = mongoose.model('category', categorySchema, 'category');


// 菜品表
const cuisineSchema = new mongoose.Schema({
    img: String, // 菜品图片
    name: String, // 菜品名称
    price: Number, // 价格
    desc: String,  // 描述
    nums: Number,  // 售卖总数量
    daynum: Number, // 每日数量
    num: Number, //每个订单的售卖数量
    addTime:String, // 添加时间
    daySeelNum:Number,
    cid: {
        type: mongoose.Types.ObjectId,
        ref: 'category'
    },
   
})
// 菜品表
let cuisineModel = mongoose.model('cuisine', cuisineSchema, 'cuisine');

// 售卖表
const cuisineshell = new mongoose.Schema({
    cuisineid: { //菜品id
        type: mongoose.Types.ObjectId,
        ref: 'cuisine'
    },
    userid: String, // 用户id
    shelltime: String, // 售卖时间

})
// 售卖表
let cuisineshellModel = mongoose.model('cuisineshell', cuisineshell, 'cuisineshell');

// 订单信息表
const orderSchema = new mongoose.Schema({
    userid: String, // 用户id
    orderid: String, // 订单id
    ordertime: String, // 订单时间
    orderstatus: String, // 订单状态
    orderprice: Number, // 订单价格
})
// 订单信息表
const orderModel = mongoose.model('order', orderSchema, 'order');

// 用户表
const userSchema = new mongoose.Schema({
    username: String,
    phone: String,
    time: Date,
    sex:String,
    age:Number,
    // 会员
    vip: String,
    Table_times: String
})


const userModel = mongoose.model('user', userSchema, 'user');

// 单独点菜表
const MenuSchema = new mongoose.Schema({
    name: String, //菜名
    price: String, //价格
    num: Number, //数量
    pid: {
        type: mongoose.Types.ObjectId,
        ref: 'user'

    },
})

const MenuModel = mongoose.model('menu', MenuSchema, 'menu');
// 首页UserOrder表
const UserOrderSchema = new mongoose.Schema({

    name:String,//客户名
    personNum:Number,//就餐人数
    userid:{
        type:mongoose.Types.ObjectId,
        ref:'user'
    },//和用户表关联
    menuid:{
        type:mongoose.Types.ObjectId,
        ref:'menu'
    },//和单独点菜表关联
    state:Number,//订单状态 
    // 0 进行中 1 准备中 2 未支付
    // 包间名
    Table_name:String,
    
    //所点菜品个数
    Menu_num:Number,
    //下单时间
    ordertime:String,
    //订单总价
    orderprice:Number,
    //服务员id
    waiterid:String

    
})

const UserOrderModel = mongoose.model('userorder', UserOrderSchema, 'userorder');



// 其他店铺
const othershopSchema = new mongoose.Schema({
    name: String, //店铺名称
    phone: String, //店铺电话
    dianzhang:String, //店长
    jingli:String, //经理
})
const othershopModel = mongoose.model('othershop', othershopSchema, 'othershop');

// 用户表
const AdminSchema = mongoose.Schema({
    username: String,
    password: String,
    userphone: Number,
    avatar: String,
    role:String,
})
const AdminModel = mongoose.model('Admin', AdminSchema, 'Admin');

// 暴露在需要的页面进行导入
module.exports = { cuisineModel, orderModel, userModel, categoryModel,MenuModel,othershopModel,AdminModel,cuisineshellModel,UserOrderModel};
